import clickhouse_connect
import random
from datetime import datetime, timedelta
import uuid

connect_info = {
    'port': 8123,
    'host': '192.168.103.43',
    'username': 'admin',
    'password': '@Abcd1234',
    'database': 'saas'
}
client = clickhouse_connect.get_client(**connect_info)
column_list = [
    'log_id', 'log_time', 'rpt_name', 'uuid', 'generate_time', 'statis_date', 'master_account', 'user_name',
    'org_name', 'org_code', 'org_name_path', 'master_expire_time', 'account_belong', 'slave_account',
    'slave_expire_time', 'involve_system', 'work_no', 'authorize_effect_time', 'authorize_expire_time',
    'report_data_type', 'statis_time', 'data_code'
]
insert_data = []
num = 0
table_name = 'er_app_master_slave_bind_all'
while num < 20001:
    log_id = str(random.randint(10 ** 14, 10 ** 16))
    str_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    log_time = datetime.strptime(str_time, '%Y-%m-%d %H:%M:%S')
    rpt_name = 'test'
    str_uuid = str(uuid.uuid4())
    generate_time = str_time
    statis_date = datetime.now().strftime('%Y-%m-%d')
    master_account = 'mijy'
    user_name = '米佳运'
    org_name = '行业销售服务室'
    org_code = '203'
    org_name_path = '上海移动/政企客户部/业务管理室'
    master_expire_time = '2025-12-31 23:59:59'
    account_belong = '系统账号'
    slave_account = 'JS429'
    slave_expire_time = master_expire_time
    involve_system = 'CRM'
    work_no = 'NO' + str(num).zfill(6)
    authorize_effect_time = '2025-01-01 00:00:00'
    authorize_expire_time = master_expire_time
    report_data_type = 'monthData'
    yesterday_time = datetime.now() - timedelta(days=1)
    str_yesterday = yesterday_time.strftime('%Y-%m-%d %H:%M:%S')
    statis_time = datetime.strptime(str_yesterday, '%Y-%m-%d %H:%M:%S')
    data_code = 'data_code' + str(num).zfill(6)
    insert_data.append(
        [log_id, log_time, rpt_name, str_uuid, generate_time, statis_date, master_account, user_name,
         org_name, org_code, org_name_path, master_expire_time, account_belong, slave_account,
         slave_expire_time, involve_system, work_no, authorize_effect_time, authorize_expire_time,
         report_data_type, statis_time, data_code])
    num += 1
client.insert(table_name, data=insert_data, column_names=column_list)
client.close()
